/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: GameOptionScreen.java 639 2010-07-30 05:53:30Z Harry $
 *   $LastChangedDate: 2010-07-30 05:53:30 +0000 (Fri, 30 Jul 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.ui.screen;

import battlefield.resource.Graphics;
import battlefield.ui.component.NormalWhiteButton;
import battlefield.util.ComponentDecorator;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author Yong Peng
 */
public class GameOptionScreen extends Screen implements ActionListener {

    private JLabel gameOptionLab;
    private JLabel playerNameLab;
    private JTextField playerNameText;
    private JButton backBut;
    private JButton saveBut;

    public GameOptionScreen() {
        initComponents();
    }

    private void initComponents() {
        gameOptionLab = new JLabel(new ImageIcon(Graphics.SCREEN_TITLE_GAME_OPTIONS.getImage()));
        playerNameLab = ComponentDecorator.decorateLabel(playerNameLab, "Player Name");
        playerNameText = ComponentDecorator.decorateTextfield(playerNameText, 15, getSession().getPlayerName());
        backBut = new NormalWhiteButton("Back", this);
        saveBut = new NormalWhiteButton("Save", this);
        this.setBackgroundImage(Graphics.BACKGROUND_MISC.getImage());
        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        layout.setHorizontalGroup(
                layout.createSequentialGroup().addGap(50, 50, 50).addGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(gameOptionLab).addGroup(layout.createSequentialGroup().addComponent(playerNameLab).addComponent(playerNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGroup(layout.createSequentialGroup().addComponent(backBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(saveBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))));
        layout.setVerticalGroup(
                layout.createSequentialGroup().addGap(50, 50, 50).addComponent(gameOptionLab).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(playerNameLab).addComponent(playerNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(backBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(saveBut, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)));
    }

    /* Begin Region: State Pattern */
    @Override
    public Screen save() {
        getSession().setPlayerName(playerNameText.getText());
        return new GameMenuScreen();
    }

    @Override
    public Screen back() {
        return new GameMenuScreen();
    }
    /* End Region: State Pattern */

    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(saveBut)) {
            getGUI().save();
        } else if (e.getSource().equals(backBut)) {
            getGUI().back();
        }
    }
}
